package com.conversationboard.fulltext.search.hit;

import java.sql.SQLException;
import java.util.Date;

import org.joda.time.DateTime;

import com.conversationboard.model.Boards;
import com.conversationboard.model.User;

public class ThreadHit implements Comparable<ThreadHit> {

	private int boardId;
	private int threadId;
	private String title;
	private String displayName;
	private String loginId;
	private DateTime timestamp;
	private boolean deleted;


	public boolean isDeleted() {
		return deleted;
	}


	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}


	public String getBoardName() throws SQLException {
		return Boards.getBoard(boardId).getName();
	}


	public int compareTo(ThreadHit threadHit) {
		return this.timestamp.compareTo(threadHit.timestamp);
	}


	public Date getTimestampAsDate() {
		return timestamp.toDate();
	}


	public int getBoardId() {
		return boardId;
	}


	public void setBoardId(int boardId) {
		this.boardId = boardId;
	}


	public int getThreadId() {
		return threadId;
	}


	public void setThreadId(int threadId) {
		this.threadId = threadId;
	}


	public String getTitle() {
		return title;
	}


	public void setTitle(String title) {
		this.title = title;
	}


	public String getDisplayName() {
		return displayName;
	}


	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}


	public String getLoginId() {
		return loginId;
	}


	public void setLoginId(String loginId) {
		this.loginId = loginId;
	}


	public DateTime getTimestamp() {
		return timestamp;
	}


	public void setTimestamp(DateTime timestamp) {
		this.timestamp = timestamp;
	}


	public boolean canBePostedOnBy(User user) throws SQLException {

		if (user.isAbleToPost(this.boardId) && (!this.isDeleted())) {
			return true;
		} else {
			return false;
		}

	}

}
